package com.zsj.juc.Atomic;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @author zsj
 * @version 1.0
 * @date 2024/5/17 14:19
 * @description 原子数组
 */
@Slf4j
public class AtomicArrayDemo {
    public static void main(String[] args) {
        AtomicIntegerArray atomicIntegerArray =
                new AtomicIntegerArray(new int[]{1, 2, 3});
        for (int i = 0; i < atomicIntegerArray.length(); i++) {
            log.info("index:{} value:{}", i, atomicIntegerArray.get(i));
        }
        atomicIntegerArray.getAndIncrement(0);
        System.out.println(atomicIntegerArray.get(0));

        System.out.println(atomicIntegerArray.compareAndSet(0, 2, 3));

        System.out.println(atomicIntegerArray.get(0));

    }
}
